﻿using System;

namespace ShenLan.Common
{
    public class ReadConfig
    {
        /// <summary>
        /// 根据key读取Appsettings配置中的Value
        /// </summary>
        /// <param name="key">key值</param>
        /// <returns>相应key键的value值</returns>
        public static string ReadAppsettingsValue(string key)
        {
            try
            {
                return System.Configuration.ConfigurationManager.AppSettings[key].ToString();
            }
            catch 
            {
                return "ReadAppsettingValueError";
            }
        }

        /// <summary>
        /// 根据连接串名称读取web.config中连接串的值
        /// </summary>
        /// <param name="strName">connectionString的name</param>
        /// <returns>web.config中的ConnectionString</returns>
        public static string ReadConnectionString(string strName)
        {
            try
            {
                return System.Configuration.ConfigurationManager.ConnectionStrings[strName].ConnectionString;
            }
            catch
            {
               return "ReadConnectionStringError";
            }
        }
    }
}